package com.example.springboot01.controller;

import com.example.springboot01.entity.Professor;
import com.example.springboot01.entity.Score;
import com.example.springboot01.req.PageQueryReq;
import com.example.springboot01.resp.Response;
import com.example.springboot01.resp.enums.CommonRespEnum;
import com.example.springboot01.resp.enums.ProfessorRespEnum;
import com.example.springboot01.service.ProfessorService;
import com.example.springboot01.service.ScoreService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/api/v1/score")
public class ScoreController {

    @Resource
    private ScoreService scoreService;

    @PostMapping
    public Response add(@RequestBody Score score, HttpSession session){
        scoreService.addScore(score, session);
        return Response.ok(null);
    }

    @PutMapping
    public Response update(@RequestBody Score score){
        scoreService.updateById(score);
        return Response.response(CommonRespEnum.UPDATE_OK);
    }

    @DeleteMapping("/{id}")
    public Response delete(@PathVariable Integer id){
        return Response.response(CommonRespEnum.DELETE_OK);
    }

    @GetMapping
    public Response list(){
        return Response.ok(scoreService.list());
    }

    @GetMapping("/page")
    public Response page(PageQueryReq req, HttpSession session){
        return Response.ok(this.scoreService.getPage(req, session));
    }


    @GetMapping("/student")
    public Response queryScore(){
        return Response.ok(this.scoreService.queryScore());
    }

}
